//
//  MyViewController.m
//  RunTime的一些深入
//
//  Created by ZhouFahong on 16/7/29.
//  Copyright © 2016年 ZhouFahong. All rights reserved.
//

#import "MyViewController.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import "MyObject.h"
#import "Person.h"
#import "Student.h"

#define KSCREENSIZE         ([UIScreen mainScreen].applicationFrame.size)  //屏幕可用尺寸

@implementation MyViewController

-(void)viewDidLoad{
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
    [self.view addGestureRecognizer:tap];
    
    [tap setNumberOfTapsRequired:1];
    [tap setNumberOfTouchesRequired:1];
    
    
    [tap addTarget:self action:@selector(dimis)];
    
    
    IMP imp = imp_implementationWithBlock(^(id obj,NSString* str,NSString *count){
        
        NSLog(@"object:%@",NSStringFromClass([obj class]));
        MyObject *object = (MyObject*)obj;
        NSLog(@"name=%@,status=%@",object.name,object.status);
        NSLog(@"string = %@,count = %@",str, count);
    });
    
    IMP iii = imp_implementationWithBlock(^(id obj){
        
    });
    class_addMethod([MyObject class], @selector(testBlock:), imp, "v@:@:@:");
    
    MyObject *runtime = [[MyObject alloc]init];
    
    NSInteger aaa = 100;
    NSString *str = @"runtime";
    
    runtime.name = [str copy];
    
    runtime.status = str;
    
    [runtime performSelector:@selector(testBlock:) withObject:@"helle word" withObject:@"100"];
    
    [self personTest];
    [self viewFramWithBodor];
    [self unknownSelector];
}

// Receiver在收到unknown selector后，首先将调用其本类的resolveInstanceMethod:方法
-(void)unknownSelector{
    Student *noah = [[Student alloc]init];
//    noah.name = @"Noah";
    [noah performSelector:@selector(setName:) withObject:@"Noah"];
    NSLog(@"name of this student：%@",noah.name);
    // 消息转发
    [noah performSelector:@selector(method1)];
}

-(void)viewFramWithBodor{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, 80, KSCREENSIZE.width-20, 200)];
    view.layer.borderWidth = 1;
    view.layer.borderColor = [UIColor grayColor].CGColor;
    view.layer.cornerRadius = 2;
    view.layer.masksToBounds = YES;
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
}

-(void)personTest{
    
    Person *person = [[Person alloc]init];
    person.name = @"Noah";
    person.age = @"28";
    person.sex = @"男";
    person.address = @"bj";
    person.num = 142597;
    
    NSLog(@"%@",[person description]);
    
}


-(void)dimis{
    
//    UIGestureRecognizer
//    UITapGestureRecognizer
//    UIPinchGestureRecognizer
//    UIRotationGestureRecognizer
//    UISwipeGestureRecognizer
//    UIPanGestureRecognizer
//    UILongPressGestureRecognizer
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

-(NSString *)description{
    return @"";
}

@end
